package com.yunhe.abnormal.repository.base;

import com.yunhe.abnormal.domain.base.AlarmSmsConfig;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 异常短信接收人配置数据仓库
 * @author liuronglei
 */
@Repository
public interface AlarmSmsConfigRepository extends Neo4jRepository<AlarmSmsConfig, Long> {
    @Query("match (anc:AlarmNotifyConfig)-[:SMS_DEST_OF]->(sc:AlarmSmsConfig) where ID(anc)={alarmNotifyConfigId}" +
            " return (sc),(sc)-[:USER_OF]->(:User) order by sc.sn")
    List<AlarmSmsConfig> findByNotifyConfig(@Param("alarmNotifyConfigId") Long alarmNotifyConfigId);

    @Query("match (anc:AlarmNotifyConfig),(sc:AlarmSmsConfig) where ID(sc)={id} and ID(anc)={alarmNotifyConfigId}" +
            " create (anc)-[:SMS_DEST_OF]->(sc) return sc")
    void bindNotifyConfig(@Param("id") Long id, @Param("alarmNotifyConfigId") Long alarmNotifyConfigId);

    @Query("match (u:User),(sc:AlarmSmsConfig) where ID(sc)={id} and ID(u)={userId}" +
            " create (sc)-[:USER_OF]->(u) return sc")
    void bindUser(@Param("id") Long id, @Param("userId") Long userId);
}
